package com.xmh.reptile.service;

import cn.hutool.core.io.FileUtil;
import com.xmh.reptile.util.RedisMockUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

public class ReadBookService {

    public void test1() throws InterruptedException {
        String indexStr = "豪强大族一旦强大到某种程度，基本可以控制一方，朝廷官员到了地方若不与之河流，基本没法";
//        String indexStr = "";

        long speed = 90;

        String charsetName = "UTF-8";
        String bookStr = FileUtil.readString(new File("C:\\Users\\xmh\\Desktop\\小说\\李环李长河soduso2022-02-07 10-50-35.txt"), charsetName);

        String key = "ReadBookService_全球高武_对比";
        Integer index = (Integer) RedisMockUtil.get(key);

        String[] split1 = bookStr.split("\n");

        if (StringUtils.isNotEmpty(indexStr)) {
            for (int i = 0; i < split1.length; i++) {
                String s = split1[i];
                if (StringUtils.isNotEmpty(s) && s.contains(indexStr)) {
                    index = i;
                }
            }
        }

        for (int i = index; i < split1.length; i++) {
            String s = split1[i];
            if (StringUtils.isNotEmpty(s)) {
                System.out.println(s);
                RedisMockUtil.set(key, i);
                Thread.sleep(s.length() * speed);
            }
        }
    }

    public void test2() throws InterruptedException {
        String charsetName = "UTF-8";
        String bookStr = FileUtil.readString(new File("C:\\Users\\xmh\\Desktop\\全球高武_对比.txt"), charsetName);

        String[] split1 = bookStr.split("\n");

        for (int i = 0; i < split1.length; i++) {
            String s = split1[i];
            if (StringUtils.isNotEmpty(s) && s.contains("“坤王，别客气，三大护教来啊！正想杀个圣人练练手，哈哈，来啊！” ")) {
                System.out.println(i);
            }
        }
    }
}
